<!-- 投诉已办 -->
<template>
	<view>
		<view class="no-warpper" v-if="isLong">
			<!-- 有数据 渲染列表 -->
			<view v-if="hasInfo">
				<view class="scroll-box">
					<view class="nl-shadow-box card-box" v-for="(item,index) in complaintList" :key="index">
						<view class="nl-flex-list title">
							<view>{{item.complaintId}}</view>
							<text :class="item.typeCd == '809001' ? 'yellow':'red'">{{item.typeCdName}}</text>
						</view>
						<view class="nl-flex-list">
							<view class="content" @click="details(item)">
								<view class="item">
									<view>{{item.typeCdName}}人</view>
									<text>：</text>
									<view>{{item.complaintName}}</view>
								</view>
								<view class="item">
									<view>所属房屋</view>
									<text>：</text>
									<view>{{item.floorNum +'-' + item.unitNum+'-' +item.roomNum}}</view>
								</view>
								<view class="item">
									<view>电话</view>
									<text>：</text>
									<view>{{item.tel}}</view>
								</view>
								<view class="item">
									<view>{{item.typeCdName}}时间</view>
									<text>：</text>
									<view>{{item.createTime}}</view>
								</view>
								<view class="item">
									<view>{{item.typeCdName}}内容</view>
									<text>：</text>
									<view>{{item.context}}</view>
								</view>
							</view>
						</view>
						<view class="botton-flex">
							<view class="button-mini line">
								<button @click="details(item)">详情</button>
							</view>
						</view>
					</view>
					<u-loadmore :status="status" />
				</view>
			</view>
			<!-- 无数据 渲染缺省图 -->
			<view v-if="hasInfo == false">
				<noData :noDataText="noDataText"></noData>
			</view>
		</view>

		<view v-else>
			<netError v-if="!hasNet" @refresh="refresh()"></netError>
		</view>
	</view>
</template>

<script>
	import {
		getFinishComplaints
	} from 'api/complaint';
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				listBox: [], // 避免上拉刷新时，页面出现空白
				complaintList: [],
				page: 1,
				records: 0,
				status: 'loadmore',


				isLong: false, // 是否加载完成
				hasNet: true, // 是否有网络
				hasInfo: '', // 是否有数据
				noDataText: '暂无数据~',
			}
		},
		computed: {
			...mapState('user', ['userInfo', 'userCommunity'])
		},
		onLoad() {
			this.page = 1
			this.records = 0
			this.listBox = []
			this.getFinishComplaints(this.page)
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.records = 0
			this.listBox = []
			this.getFinishComplaints(1)
		},
		// 上拉加载
		onReachBottom() {
			console.log('页面触底了')
			if (this.status == 'loading') { // 防止多次触发

			} else {
				this.status = 'loading';
				if (this.page <= this.records) {
					this.getFinishComplaints(this.page)
				} else {
					this.status = 'nomore';
				}
			}
		},
		methods: {
			/**
			 * 获取投诉已办列表
			 */
			getFinishComplaints(page) {
				var that = this
				const data = {
					userId: this.userInfo.userId,
					communityId: this.userCommunity.communityId,
					page: page,
					row: 10
				}
				getFinishComplaints(data).then((res) => {
					if(res.code == 500){
						uni.showToast({
							title:res.msg,
							duration: 5000,
							icon:'error'
						})
					}
					if (res.records == 0) { //暂无数据
						that.hasInfo = false
						that.isLong = true;
						uni.hideLoading()
						uni.stopPullDownRefresh()
						return;
					}


					that.records = res.records
					if (that.records == that.page) {
						that.status = 'nomore'
					} else {
						that.status = 'loadmore'
					}
					that.page++
					uni.stopPullDownRefresh()
					for (let i of res.complaints) {
						that.listBox.push(i)
					}
					that.complaintList = that.listBox

					that.isLong = true
					that.hasInfo = true

				}).catch(function(reason) {
					uni.stopPullDownRefresh()
					// 处理网络错误
					that.hasNet = false
					that.isLong = false
				})
			},
			/**
			 * 投诉详情
			 */
			details(params) {
				console.log(params)
				let roomName = `${params.floorNum}栋${params.unitNum}单元${params.roomNum}室`
				uni.navigateTo({
					url: `/pages/home/myAuditComplaints/complaintsDetails/complaintsDetails?complaintId=${params.complaintId}&roomName=${roomName}&typeCdName=${params.typeCdName}&complaintName=${params.complaintName}&tel=${params.tel}&createTime=${params.createTime}&context=${params.context}&roomId=${params.roomId}`
				});
			},
			/**
			 * 刷新
			 */
			refresh() {
				this.complaintList = []
				this.page = 1
				this.records = 0
				this.getFinishComplaints(1)
			}
		}
	}
</script>

<style lang="scss">
	.scroll-box {
		width: 100%;
		margin-bottom: 32rpx;
	}
</style>
